
from PSData import PSDataServer
from PSData import PSData
import  time
import threading

class DataBulider(PSDataServer):
    def __init__(self) -> None:
        super().__init__()
        self._PsServerEnable(0x0020, 0x01)

    def StartBuilderData(self):
        task_ = threading.Thread(target=self.SendData)
        task_.start()
        
    def SendData(self) -> None:
        time.sleep(1)
        data_ = PSData(
            header='GetWidgetList',
            value='This is a data from DataBulider'
        )
        while(True):
            if (self._isPsServiceStart):
                self.PsSetDataToAsync(0x0002, 0x01, data_, self.SendResult)
                # self.PsSetDataToSync(0x0002, 0x01, data_)
                # self.PsGetDataFromSync(0x0002, 0x01, data_)
                # print(data_.value)
                time.sleep(0.01)
            else:
                break

    def SendResult(self, result: 'bool') -> None:
        print('DataBulider接收到了回复结果{0}'.format(result))